package artid.com.artc;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

import artid.com.artc.adapter.SPAuctionHotAdapter;
import artid.com.artc.adapter.SPAuctionPreviewAdapter;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SPAuctionHotActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener, BaseQuickAdapter.RequestLoadMoreListener {

    protected Context mContext;

    @BindView(R.id.rv_list)
    RecyclerView mRecyclerView;
    @BindView(R.id.swipeLayout)
    SwipeRefreshLayout mSwipeRefreshLayout;
    @BindView(R.id.tv_title_name)
    TextView title;//title
    @BindView(R.id.title_right)
    ImageView right;//title
    SPAuctionHotAdapter adapter;
    protected boolean onRefreshJudge = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sp_auction_hot);
        mContext = this;
        ButterKnife.bind(this);
        title.setText(R.string.sp_auction_preview);
        initList();
    }

    private void initList() {
        onRefreshJudge = true;
        mSwipeRefreshLayout.setOnRefreshListener(this);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        List arr = new ArrayList<String>();
        arr.add("");
        arr.add("");
        arr.add("");
        adapter = new SPAuctionHotAdapter(mContext, arr);
        adapter.setOnLoadMoreListener(this, mRecyclerView);
        adapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);

        mRecyclerView.setAdapter(adapter);
        mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {

            }
        });
    }

    @OnClick({R.id.title_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_back:
                finish();
                break;
        }
    }

    /**
     * [页面跳转]
     *
     * @param clz
     */
    public void startActivity(Class<?> clz) {
        startActivity(new Intent(this, clz));
    }

    @Override
    public void onRefresh() {
        onRefreshJudge = true;
        if (onRefreshJudge) {
            List arr = new ArrayList<String>();
            arr.add("");
            arr.add("");
            arr.add("");
            arr.add("");
            adapter.setNewData(arr);
            mSwipeRefreshLayout.setRefreshing(false);
            adapter.setEnableLoadMore(true);
            onRefreshJudge = false;
        }
    }

    @Override
    public void onLoadMoreRequested() {
        adapter.loadMoreEnd(true);
    }
}
